package com.paipaideli.common.utils;

import android.text.TextUtils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class StringUtil {

	//非空判断
	public static boolean isEmpty(String str) {
		return str == null || str.length() == 0 ;
	}

	// 判别是否包含Emoji表情
	public static boolean hasEmoji(String str) {
		if (TextUtils.isEmpty(str)) {
			return false;
		}
		int len = str.length();
		for (int i = 0; i < len; i++) {
			if (isEmojiCharacter(str.charAt(i))) {
				return true;
			}
		}
		return false;
	}

	private static boolean isEmojiCharacter(char codePoint) {
		return !((codePoint == 0x0) ||
				(codePoint == 0x9) ||
				(codePoint == 0xA) ||
				(codePoint == 0xD) ||
				((codePoint >= 0x20) && (codePoint <= 0xD7FF)) ||
				((codePoint >= 0xE000) && (codePoint <= 0xFFFD)) ||
				((codePoint >= 0x10000) && (codePoint <= 0x10FFFF)));
	}

	//判断是否包含中文字符
	public static boolean hasChinese(String sequence) {
		if (TextUtils.isEmpty(sequence)) {
			return false;
		}
		final String format = "[\\u4E00-\\u9FA5\\uF900-\\uFA2D]";
		boolean result = false;
		Pattern pattern = Pattern.compile(format);
		Matcher matcher = pattern.matcher(sequence);
		result = matcher.find();
		return result;
	}

	//判断是否包含空格
	public static boolean hasSeparator(String sequence) {
		if (TextUtils.isEmpty(sequence)) {
			return false;
		}
		return sequence.contains(" ");
	}

	public static boolean isTTicarPasswordNotRight(String s) {
		if (TextUtils.isEmpty(s)) {
			return true;
		}
		if (hasEmoji(s) || hasChinese(s) || hasSeparator(s)) {
			return true;
		} else {
			return false;
		}
	}
}
